package com.factory._14iterator;

/**
 * @author Qinye
 * @date 2023/8/13 17:01
 */
public class ConcreteIterator implements Iterator {
    private int index = 0;
    private int size = 0;
    private ConcreteAggregate concreteAggregate;

    public ConcreteIterator(ConcreteAggregate concreteAggregate) {
        this.concreteAggregate = concreteAggregate;
        this.size = concreteAggregate.size();
        this.index = 0;
    }

    @Override
    public void first() {
        index = 0;
    }

    @Override
    public void next() {
        if (index < size) {
            index++;
        }
    }

    @Override
    public boolean isDone() {
        return index>=size;
    }

    @Override
    public Object currentItem() {
        return concreteAggregate.getElement((index));
    }
}
